import { getUserInfo } from "../utils/storage"

Component({
  data: {
    show: true,
    user: {} as WxUser, 
    selected: 0,
    color: "#000",
    selectedColor: "#4b5cc4",
    list: [
      {
        text: "首页",
        pagePath: "/pages/index/index",
        iconPath: "/static/icons/index.png",
        selectedIconPath: "/static/icons/index_active.png"
      },
      {
        text: "我的",
        pagePath: "/pages/me/me",
        iconPath: "/static/icons/me.png",
        selectedIconPath: "/static/icons/me_active.png"
      }
    ]
  },
  lifetimes: {
    attached() {
      const user = getUserInfo()
      this.setData({
        user
      })
    }
  },
  methods: {
    switchTab(e: any) {
      const data = e.currentTarget.dataset
      const url = data.path
      wx.switchTab({url})
      this.setData({
        selected: data.index
      })
    },
    toAddPeer() {
      if(this.data.user.isVip) {
        //是vip直接跳转到发布页面
        wx.navigateTo({
          url: '/pages/addPeer/addPeer'
        })
      } else {
        wx.showModal({
          title: '未开通会员',
          content: '需开通会员才可发布车源，是否开通',
          success(res: any) {
            if (res.confirm) {
              wx.navigateTo({
                url: '/pages/getVip/getVip'
              })
            } else if (res.cancel) {}
          }
        })
      }
    }
  }
})
